package com.itmk.web.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.goods.entity.Goods;
import com.itmk.web.goods.entity.WaterfallListParm;
import com.itmk.web.goods.service.GoodsService;
import com.itmk.web.order.entity.Order;
import com.itmk.web.order.entity.OrderListParm;
import com.itmk.web.order.entity.OrderVo;
import com.itmk.web.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;

    @PostMapping("createOrder")
    public ResultVo createOrder(@RequestBody Order order){
        orderService.createOrder(order);
        return ResultUtils.success("create order success");
    }
    //根据买家id查询订单列表(购买列表)
    @GetMapping("/getOrderList")
    public ResultVo getOrderList(WaterfallListParm parm) {
        IPage<Goods> list = goodsService.getOrderList(parm);
        return ResultUtils.success("get orderlist success", list);
    }


    //根据卖家id查询订单列表(出售列表)
    @GetMapping("/getSalesOrderList")
    public ResultVo getSalesOrderList(WaterfallListParm parm) {
        IPage<Goods> list = goodsService.getSalesOrderList(parm);
        return ResultUtils.success("get sales orderlist success", list);
    }

    //后台管理生成订单列表
    @GetMapping("getList")
    public ResultVo getList(OrderListParm parm){
        IPage<OrderVo> list =orderService.getList(parm);
        return ResultUtils.success("get oreder list success",list);

    }

}
